/**
 * Project Name:kany-project-spring-boot
 * File Name:IndexController.java
 * Package Name:me.kany.project.controller
 * Date:2016年3月19日上午6:24:14
 * Copyright (c) 2016, Jason.Wang All Rights Reserved.
 */

package me.kany.project.spring.boot.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import me.kany.project.spring.boot.model.BlogDoc;
import me.kany.project.spring.boot.service.IBlogDocService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * ClassName:IndexController <br/>
 * Function: 创建首页的页面控制. <br/>
 * Date:     2016年3月19日 上午6:24:14 <br/>
 * @author Jason.Wang
 * @version
 * @since JDK 1.7
 * @see
 */
@RestController
public class IndexController {

    private Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Autowired
    private IBlogDocService blogDocService;

    /**
     *
     * index:默认访问的首页信息. <br/>
     *
     * @author Jason.Wang
     * @return
     * @since JDK 1.7
     */
    @RequestMapping("/")
    public ModelAndView index(BlogDoc blogDoc) {
        ModelAndView result = new ModelAndView("front/index");
		PageInfo<BlogDoc> blogDocs;
		try {
			blogDocs = blogDocService.queryBlogDocListByPageInfo(blogDoc);
			result.addObject("pageInfo", blogDocs);
		} catch (Exception e) {
			e.printStackTrace();
		}
		result.addObject("queryParam", blogDoc);
		result.addObject("page", blogDoc.getPage());
		result.addObject("rows", blogDoc.getRows());
        result.addObject("today", new Date());
        logger.debug("请求数据：" + JSONObject.toJSONString(blogDoc));
        return result;
    }
}
